﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Hook : MonoBehaviour {
	GameObject hook;
	GameObject playerRef;

	// Use this for initialization
	void Start () {
		hook = this.gameObject;
		playerRef = GameObject.Find ("player");
		//GameObject.Find ("player").GetComponent<DistanceJoint2D> ().enabled = true;
	}


	void Update () {

	}
	void OnCollisionEnter2D(Collision2D col){
		hook.rigidbody2D.isKinematic = true;
		if(col.collider != playerController.standingOn[0]){
			playerRef.GetComponent<DistanceJoint2D> ().enabled = true;

			playerRef.GetComponent<DistanceJoint2D> ().connectedAnchor = col.contacts [0].point;
			playerRef.GetComponent<DistanceJoint2D> ().distance = 0.5f;
			playerController.gripped = true;

		}
		Destroy (hook);

		playerController.placeOne = false;
	}

}
